﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using Nvigorate.Common;

namespace Nvigorate.Test.Common
{
    /// <summary>
    /// Summary description for DelimitedBuilderTest
    /// </summary>
    [TestClass]
    public class DelimitedBuilderTest
    {
        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext { get; set; }

        #region Additional test attributes

        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //

        #endregion

        [TestMethod]
        public void DelimiterTrimTest()
        {
            string input = "This is a test";
            DelimitedBuilder builder = new DelimitedBuilder(" :) ");
            foreach (string word in input.Split(' '))
            {
                builder.Append(word);
            }
            Assert.AreEqual(builder.ToString(), "This :) is :) a :) test");
        }

        [TestMethod]
        public void ConstructorTrimTest()
        {
            string input = "This is a test";
            Assert.AreEqual(DelimitedBuilder.Construct(input.Split(' '), " :) "), "This :) is :) a :) test");
        }

        [TestMethod]
        public void WordTrimTest()
        {
            string input = "EMPLOYID EMPLOYID EMPLOYID";
            Assert.AreEqual(DelimitedBuilder.Construct(input.Split(' '), " AND "), "EMPLOYID AND EMPLOYID AND EMPLOYID");
        }

        [TestMethod]
        public void AppendFormatTest()
        {
            string format = "{0} plus {0} is {1}";
            string answer = "1 plus 1 is 2. 2 plus 2 is 4. 4 plus 4 is 8. 8 plus 8 is 16";
            DelimitedBuilder builder = new DelimitedBuilder(". ");

            for (int i = 1; i <= 8; i += i)
            {
                builder.AppendFormat(format, i, i + i);
            }

            Assert.AreEqual(builder.ToString(), answer);
        }
    }
}